//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

using ProjectBase.Core;
using ProjectBase.Core.Web;
using ProjectBase.Mvc;
using ProjectBase.Mvc.Controllers;

using $prjsn$.Common;
using $prjsn$.Common.Business.Services;
using $prjsn$.Common.Controllers.Services;
using $prjsn$.Common.Models.Services;
using $prjsn$.Entity.Services;

namespace $prjsn$.Controllers.Services
{
    /// <summary>
    ///     All actions for User
    /// </summary>
    public class UserController : EntityController<User, UserFilter, IUserModel, IUserFacade>, IUserController
    {
        #region OnList
        /// <summary>
        ///     Set columns for List View
        /// </summary>
        protected override IEnumerable<IItemToDisplay> LoadItemsToDisplay(UserFilter filter)
        {
            return Facade.Find(filter)
                .Select(i => new ItemToDisplay
                {
                    ID = i.IDToDisplay,
                    Description = i.ToDisplay(),
                    Items = new List<ICellDescription>
                    {
                        i.Cell(e => e.Login),
                        i.Cell(e => e.LastName),
                        i.Cell(e => e.FirstName),
                        i.Cell(e => e.ID, new CellDescription {Align = Align.right, Format = "N0"}),
                    }
                } as IItemToDisplay);
        }

        /// <summary>
        ///     Provides columns for Excel
        /// </summary>
        protected override IEnumerable<IEnumerable<IExCell>> LoadExcelItemsToDisplay(UserFilter filter)
        {
            return Facade.Find(filter)
                .Select(i => new List<IExCell>
                {
                    i.ExCell(e => e.ID),
                    i.ExCell(e => e.Login),
                    i.ExCell(e => e.LastName),
                    i.ExCell(e => e.FirstName),
                });
        }
        #endregion OnList

        #region OnBefore
        #endregion OnBefore

        #region abstract ClearFilter
        /// <summary>
        ///     Pre-sets filtering filters
        /// </summary>
        protected override UserFilter ClearFilter()
        {
            var filter = base.ClearFilter();
            // TODO set the MVC defaults e.g.: filter.OrderBy["ID"] = false;
            return filter;
        }
        #endregion ClearFilter

        #region properties
        public override string ControllerName
        {
            get { return Str.Controllers.User; }
        }

        // TODO put lazily laoded facades here
        // e.g. IUserFacade if User instance is needed
        #endregion properties
    }
}